import {test,url} from '@/api/test.js'
import router, { resetRouter } from '@/router'
import {swipe,NewShop,HomeCommend,Details,GetCart,AddCart,Search,NavFl,Login,DelCart,ClearAll} from '@/api/url.js'


const state = {
  vuexStr:"",
  vuexSwipe:"",
  vuexNewShop:'',
  vuexcommend:'',
  vuexUrl:'',
  vuexDetails:'',
  Getcart:'',
  AddCart:'',
  search:'',
  fl:'',
  GoLogin:'',
  DelCartCont:'',
  ClearCart:''
}

// 
const mutations = {
  SET_VUEXTEST:(state, data)=>{
    state.vuexStr=data
  },
  SET_Home_Swipe:(state, data)=>{
    state.vuexSwipe=data
  },
  SET_Home_NewShop:(state, data)=>{
    state.vuexNewShop=data
  },
  SET_Home_Commend:(state, data)=>{
    state.vuexcommend=data
  },
  SET_Url:(state, data)=>{
    state.vuexUrl=data
  },
  SET_Details:(state, data)=>{
    state.vuexDetails=data
  },
  SET_Cart:(state, data)=>{
    state.Getcart=data
  },
  Add_Cart:(state, data)=>{
    state.AddCart=data
  },
  SET_search:(state, data)=>{
    state.search=data
  },
  SET_NavFl:(state, data)=>{
    state.fl=data
  },
  SET_Login:(state, data)=>{
    state.GoLogin=data
  },
  SET_DelCart:(state, data)=>{
    state.DelCartCont=data
  },
  SET_ClearAll:(state, data)=>{
    state.ClearCart=data
  }
}

const actions = {
  // 测试调用api接口使用
  vuexTest({commit},data){
     return new Promise((resolve, reject)=>{
       var expressState= test()
       if(expressState){
		commit("SET_VUEXTEST",expressState+data)
         resolve(expressState)
       }else{
         reject("失败")
       }
     })

    // return express()
  },
  
  
  Home_Swipe({commit},data){
     return new Promise((resolve, reject)=>{
       var getlogin= swipe()
       if(getlogin){
  		commit("SET_Home_Swipe",getlogin+data)
         resolve(getlogin)
       }else{
         reject("失败")
       }
     })
  
    // return express()
  },
  
  
  Home_NewShop({commit},data){
     return new Promise((resolve, reject)=>{
       var newShop= NewShop()
       if(newShop){
  		commit("SET_Home_NewShop",newShop+data)
         resolve(newShop)
       }else{
         reject("失败")
       }
     })
  
    // return express()
  },
  
  Home_Commend({commit},data){
     return new Promise((resolve, reject)=>{
       var commend= HomeCommend()
       if(commend){
  		commit("SET_Home_Commend",commend+data)
         resolve(commend)
       }else{
         reject("失败")
       }
     })
  
    // return express()
  },
  
  Home_Url({commit},data){
     return new Promise((resolve, reject)=>{
       var urll= url()
       if(urll){
  		commit("SET_Url",urll+data)
         resolve(urll)
       }else{
         reject("失败")
       }
     })
  
    // return express()
  },
  
  // 详情
  Get_Details({commit},data){
     return new Promise((resolve, reject)=>{
       var Details1= Details(data)
       if(Details1){
  		commit("SET_Details",Details1+data)
         resolve(Details1)
       }else{
         reject("失败")
       }
	     // console.log(Details1,222)
     })

    // return express()
  },
  // 获取购物车列表
  Get_Cart({commit},data){
     return new Promise((resolve, reject)=>{
       var GetCartS= GetCart(data)
       if(GetCartS){
  		commit("SET_Cart",GetCartS+data)
         resolve(GetCartS)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 加入购物车
  Add_Cart({commit},data){
	  console.log(data,416)
     return new Promise((resolve, reject)=>{
       var AddCarts= AddCart(data)
       if(AddCarts){
  		commit("Add_Cart",AddCarts+data)
         resolve(AddCarts)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 搜索
  Get_Search({commit},data){
     return new Promise((resolve, reject)=>{
       var Searchs= Search(data)
       if(Searchs){
  		commit("SET_search",Searchs+data)
         resolve(Searchs)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 搜索
  Get_NavFl({commit},data){
     return new Promise((resolve, reject)=>{
       var NavFls= NavFl(data)
       if(NavFls){
  		commit("SET_NavFl",NavFls+data)
         resolve(NavFls)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 登录
  Get_Login({commit},data){
     return new Promise((resolve, reject)=>{
       var Logins= Login(data)
       if(Logins){
  		commit("SET_Login",Logins+data)
         resolve(Logins)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 删除购物车
  Get_DelCart({commit},data){
     return new Promise((resolve, reject)=>{
       var DelCarts= DelCart(data)
       if(DelCarts){
  		commit("SET_DelCart",DelCarts+data)
         resolve(DelCarts)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  // 清空购物车
  Get_ClearAll({commit},data){
     return new Promise((resolve, reject)=>{
       var ClearAlls= ClearAll(data)
       if(ClearAlls){
  		commit("SET_ClearAll",ClearAlls+data)
         resolve(ClearAlls)
       }else{
         reject("失败")
       }
  	     // console.log(Details1,222)
     })
  },
  
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
